<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Rentings;

class UserController extends Controller
{
    //更新用户信息
    public function updateuserinfo(Request $request){
           $openid = $request->post('openid');
           $postData = $request->except(['openid']);
           Rentings::where('openid',$openid)->update($postData);
           $data = Rentings::where('openid',$openid)->first();
           return ['status'=>0,'msg'=>'信息更新成功','data'=>$data];
    }
    
    //获取用户信息
    public function getuserinfo(Request $request){
        $openid = $request->get('openid');
        $userinfo = Rentings::where('openid',$openid)->first();
        return ['status'=>0,'userinfo'=>$userinfo];
    }
    
    
    
    //上传身份证信息
    public function upfile(Request $request){
        $pic = '';
        if($request->hasFile('file')){
           //将文件进行上传处理
           //store的第一个参数，指定上传文件夹的名称
           $ret = $request->file('file')->store('openid','card');
           //获取文件上传的路径
           $data = '/uploads/card/' . $ret;
           $pic = config('url.url').'/uploads/card/' . $ret;
        }else{
            return ['status' => -1 ,'msg' => '请上传文件'];
        }
        return ['status' => 0,'msg' => '文件上传成功','data'=>$data,'pic'=>$pic];
    }
    
    
}
